<?php

defined('o') || exit('404 not find file'); //防跳墙

class editlog extends model{
	public function Edit($arr){
		if (is_array($arr)) {
			switch ($arr['operate']) {
				case 'add':
					$rel = $this->adddata(
						array(
							'user_id' => $_SESSION['id'],
							'goods_id' => $arr['goodsid'],
							'message_id' => '0',
							'key_id' => $arr['type'],
							'editlog_operate' => $arr['operate'],
							'editlog_time' => time()+(8*60*60),
							'editlog_srctext' => '',
							'editlog_text' => substr($arr['text'],0,5000),
							'editlog_examine' => 0
							));
					 		if (!$rel) {
					 			return '添加失败!';
					 		}
					break;
				case 'update':
					$this->query("select goods_id from xxx_message where message_val like '%".$arr['edittext']."%'",array('goods_id'),$count);
					if ($count>0) {
						$this->adddata(
							array(
								'user_id' => $_SESSION['id'],
								'goods_id' => $arr['goodsid'],
								'message_id' => '0',
								'key_id' => $arr['type'],
								'editlog_operate' => $arr['operate'],
								'editlog_time' => time()+(8*60*60),
								'editlog_srctext' => '',
								'editlog_text' => substr($arr['text'],0,5000),
								'editlog_examine' => 0,
								'editlog_usercontent' => substr($arr['edittext'],0,500)
								));
					}else{
						return "没有找到你要申请修改的信息";
					}

					break;
				case 'delete':
					$this->query("select goods_id from xxx_message where goods_id=".$arr['goodsid']." and message_val like '%".$arr['text']."%'",array('goods_id'),$count);
					if ($count>0) {
						$this->adddata(
							array(
								'user_id' => $_SESSION['id'],
								'goods_id' => $arr['goodsid'],
								'message_id' => '0',
								'key_id' => $arr['type'],
								'editlog_operate' => $arr['operate'],
								'editlog_time' => time()+(8*60*60),
								'editlog_srctext' => '',
								'editlog_text' => substr($arr['text'],0,5000),
								'editlog_examine' => 0,
								));
					}else{
						return "没有找到你要申请删除的信息";
					}
					break;
				default:
					# code...
					break;
			}
		}
	}
	public function selEditlog($arr){
		if (is_array($arr)) {
			$text ="";
			foreach ($arr as $key => $value) {
				$text .= " $key='$value' and";
			}
			$text = trim($text,'and');
			$this->query("select goods_id from xxx_editlog where $text",array('goods_id'),$count);
			return $count <=0 ? true : false;
		}
	}

	public function getEditlog($editlog_id){
		$rel = $this->querydata(array('goods_id','key_id','editlog_operate','editlog_usercontent','editlog_text')," where editlog_id=$editlog_id");
		if (!empty($rel)) {
			foreach ($rel as $key => $value) {
				$arr = $value;
				break;
			}
			return $arr;
		}
		return false;
	}

	public function assess($editlog_id,$assess_val,$user_id){
		return $this->updata(array(
			'editlog_examine'=>$assess_val,
			'editlog_examine_time'=>time(),
			'editlog_examine_user_id'=>$user_id,
			)," editlog_id=$editlog_id");
	}

}
?>